package controller;

import annotation.Controller;
import annotation.GetMapping;
import entity.UserEntity;
import result.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController {
    @GetMapping("/user/profile")
    public ModelAndView profile(HttpServletResponse response, HttpSession session) {
        UserEntity userEntity = (UserEntity) session.getAttribute("user");
        if (userEntity == null) {
            // 未登录，跳转到登录页:
            return new ModelAndView("redirect:/");
        }
        Map<String, Object> userMap = new HashMap<>();
        userMap.put("user", userEntity);
        return new ModelAndView(userMap, "user-profile.html");
    }
}
